package inscription;
import hibernate.dao.PersonneDAO;

import java.io.Serializable;
import javax.servlet.http.HttpServletRequest;

import net.sf.hibernate.HibernateException;

import org.apache.commons.validator.Field;
import org.apache.commons.validator.Validator;
import org.apache.commons.validator.ValidatorAction;
import org.apache.commons.validator.util.ValidatorUtils;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.validator.Resources;

public class VerificationEmail implements Serializable{
	
	public static boolean valideMail(Object bean, ValidatorAction va, Field field,
			ActionMessages errors, Validator validator, HttpServletRequest request) throws HibernateException{
		
		PersonneDAO pdao = new PersonneDAO();
		
		if(pdao.findPersonneDAO(ValidatorUtils.getValueAsString(bean, field.getProperty()))){
			errors.add(field.getKey(), Resources.getActionMessage(request,va,field));
			return false;
		}
		return true;
		
	}

}
